package top.swimmer.tokenizer.dictionary;

public abstract class AbstractDictionary {

    protected int maxWordLength = 4;

    public int getMaxWordLength() {
        return maxWordLength;
    }

    AbstractDictionary() {
        build();
    }

    public abstract boolean contains(String key);
    public abstract boolean contains(String key, int start, int length);
    protected abstract void load();
    protected abstract void clear();

    private void build() {
        System.out.println("构建词典开始。。。");
        long start = System.currentTimeMillis();
        load();
        long end = System.currentTimeMillis();
        System.out.println("词典构建完成，用时：" + (end - start) + "毫秒。");
    }

    public void rebuild() {
        System.out.println("重建词典开始。。。");
        long start = System.currentTimeMillis();
        clear();
        load();
        long end = System.currentTimeMillis();
        System.out.println("词典重建完成，用时：" + (end - start) + "毫秒。");
    }
}
